package service;

import java.util.List;

import dao.WorkingMapper;
import entity.Working;
import org.apache.ibatis.session.SqlSession;
import util.MyBatisUtil;

public class WorkingService {

	WorkingMapper workingMapper=MyBatisUtil.createSqlSession().getMapper(WorkingMapper.class);

	public List<Working> getList(){
		return workingMapper.getList();
	}

	public int getCount(String title){
		return workingMapper.getCount(title);
	}

	public Working getWorking(int id){
		return workingMapper.getWorking(id);
	}

	public int save(String title,String content,int type){
		SqlSession sqlSession=null;
		try{
			sqlSession=MyBatisUtil.createSqlSession();
			int result = workingMapper.save(title,content,type);
			sqlSession.commit();
			return result;
		}catch (Exception e){
			e.printStackTrace();
			sqlSession.rollback();
			return -1;
		}finally {
			MyBatisUtil.closeSqlSession(sqlSession);
		}
	}

	public List<Working> getListPage(int currPageNo,int pageSize){
		int beginIndex = (currPageNo-1)*pageSize;
		return workingMapper.getListPage(beginIndex,pageSize);
	}

	public int getTotalCount(){
		return workingMapper.getTotalCount();
	}
}
